<template>
  <keep-alive>
    <component :is="currentComponent" @back-to-mine="onBackToMine()" @back-to-prev="onBackToPrev()"></component>
  </keep-alive>
</template>
<script setup>
import { computed } from 'vue'
import { storeToRefs } from 'pinia'
import { useBecomeCreatorRouteStore } from '@/store/become-creator-route'

const emit = defineEmits(['toPage'])

const routeStore = useBecomeCreatorRouteStore()
const { routes, deactivate } = routeStore
const { now } = storeToRefs(routeStore)
const currentComponent = computed(() => routes.find((route) => route.value === now.value).component)

const onBackToMine = () => {
  emit('toPage', 1)
  deactivate()
}

const onBackToPrev = () => {
  emit('toPage', 2, `creator-faq`)
  deactivate()
}
</script>
